<template>
    <el-button link type="primary" size="small" @click="openUpdateAction">
        <el-icon>
            <Edit/>
        </el-icon>
        编辑
    </el-button>
    <el-dialog :model-value="openUpdate"
               :lock-scroll="false"
               append-to-body
               @close="closeUpdate"
               title="详情" width="50%">
        <el-form
                label-width="auto"
                :model="${ignoreFirstHumpName}Model">
            <#list tableFields as field>
                <el-form-item required label="${field.comment}">
                    <el-input v-model="${ignoreFirstHumpName}Model.${field.name}" placeholder="${field.comment}"
                              clearable/>
                </el-form-item>
            </#list>
            <el-form-item>
                <el-button type="primary" @click="update${humpName}Action">确认更新</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>
<script setup>
    import {ref} from "vue";
    import {get${humpName}Detail, update${humpName}} from "@/api/${serviceName}/${humpName}Api.js";
    import {ElMessage} from "element-plus";
    import {useSearchStore} from "@/store/SearchStore.js";
    import {Edit} from "@element-plus/icons-vue";

    const props = defineProps(["updateId"])
    const searchStore = useSearchStore()
    const openUpdate = ref(false)
    const ${ignoreFirstHumpName}Model = ref({
        <#list tableFields as field>
        ${field.name}: '',
        </#list>
    })

    const closeUpdate = () => {
        openUpdate.value = false
    }

    const openUpdateAction = () => {
        get${humpName}Detail({id: props.updateId}).then(res => {
            if (res.success) ${ignoreFirstHumpName}Model.value = res.data
        }).finally(() => openUpdate.value = true)
    }

    const update${humpName}Action = () => {
        update${humpName}(${ignoreFirstHumpName}Model.value).then(res => {
                if (res.success) ElMessage.success(res.message)
            }
        ).finally(() => {
            openUpdate.value = false
            searchStore.noticePageRefresh()
        })
    }

</script>
